package com.ssyt.hiring.web.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ssyt.cdp.common.BaseDao;
import com.ssyt.cdp.common.PageModel;
import com.ssyt.cdp.common.util.DateUtil;
import com.ssyt.hiring.entity.ApplicationEntity;

@Repository
public class ApplicationDao extends BaseDao<ApplicationEntity, Integer> {
	/**
	 * 简历审核
	 * 
	 * @param applicationId
	 * @param applicationStatus
	 * @param handleTimeStr
	 */
	public void judgeApplication(int applicationId, int applicationStatus,
			String handleTimeStr) {
		ApplicationEntity application = load(applicationId);
		application.setStatus(applicationStatus);
		application.setHandleTime(DateUtil.parse(handleTimeStr,
				"yyyy-MM-dd HH:mm:ss"));
		update(application);
	}

	/**
	 * 简历信息查询
	 * 
	 * @return
	 */
	public PageModel<ApplicationEntity> applicationPageModel(int pageNo,
			int pageSize) {
		StringBuffer hql = new StringBuffer();
		hql.append("SELECT new ApplicationEntity(a.id,a.positionId,a.resumeId,a.status,a.appTime,a.handleTime,r.intention as resumeIntention,t.name as talentName,t.id as talentId)");
		hql.append("FROM ApplicationEntity a, ResumeEntity r,TalentEntity t ");
		hql.append("WHERE a.resumeId=r.id and r.talentId=t.id ");
		hql.append("ORDER BY a.id DESC ");
		return pageEntityByHql(pageNo, pageSize, hql.toString());
	}

	public List<ApplicationEntity> getApplicationListInfo() {

		StringBuffer hql = new StringBuffer();
		hql.append("SELECT new ApplicationEntity(a.id,a.positionId,a.resumeId,a.status,a.appTime,r.intention as resumeIntention,c.name as companyName)");
		hql.append(" FROM ApplicationEntity a, ResumeEntity r,PositionEntity p,CompanyEntity c ");
		hql.append(" WHERE a.resumeId=r.id and a.positionId=p.id and p.companyId=c.id");
		return listEntityByHql(hql.toString());
	}

}
